﻿using System.Linq;
using Daemon.Common;
using Daemon.Common.Helpers;
using Daemon.Infrustructure.EF;
using Daemon.Repository.EF.Enums;
using Daemon.Repository.Contract;
using Daemon.Model;
using System;
using System.Linq.Expressions;
using System.Collections.Generic;

namespace Daemon.Repository.EF
{
	public class TakeAwayUserRepository : Repository<TakeAwayUser>, ITakeAwayUserRepository
	{
		protected override Expression<Func<TakeAwayUser, int>> PrimaryKeyExpression => r => r.Id;

		public TakeAwayUserRepository(ApiDBContent context) : base(context)
		{
		}

		protected override void UpdateEntitiesBeforeCreate(IEnumerable<TakeAwayUser> entities, ApiDBContent context)
		{
			entities.ToList().ForEach(entity =>
			{
				entity.UserName = $"用户{CommonHelper.GenerateSurname()}";
			});
			base.UpdateEntitiesBeforeCreate(entities, context);
		}
	}
}
